﻿Public Class F_KhachHang

    Private kh As New DTOKhachHang
    Private maKH As Integer
    Private action As Integer = 1 ' 1 - insert ||  0 - update
    Sub defaultLoad()
       
    End Sub
    Sub getDataInForm()
        kh.NgaySinh = Convert.ToDateTime(txtDateNgaySinh.Text)
        kh.TenKH = txtTenKhach.Text
        kh.DienThoai = txtSodienthoai.Text
        kh.DiaChi = txtDiachi.Text
    End Sub
    Sub receiveData(ByVal kh As DTOKhachHang, ByVal a As Integer)
        txtTenKhach.Text = kh.TenKH
        txtSodienthoai.Text = kh.DienThoai
        txtDiachi.Text = kh.DiaChi
        txtDateNgaySinh.Text = kh.NgaySinh
        maKH = kh.MaKH 'Bien ma khach hang toan cuc
        action = a 'Hanh dong update
    End Sub
    Function testEmpty() As Boolean
        If txtDateNgaySinh.Text = "" Or txtTenKhach.Text = "" Or txtSodienthoai.Text = "" Or txtDiachi.Text = "" Then
            Return false
        End If
        Return True
    End Function

    Private Sub F_KhachHang_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    End Sub

    Private Sub btnGhidulieu_Click(sender As Object, e As EventArgs) Handles btnGhidulieu.Click
        If testEmpty() = False Then
            MessageBox.Show("Bạn nhập thiếu thông tin")
            Return
        End If
        getDataInForm()
        If action = 1 Then
            BUSKhachHang.KhachHang_Insert(kh)
        Else
            kh.MaKH = maKH
            BUSKhachHang.KhachHang_Update(kh)
            action = 1
        End If
        me.Close()
    End Sub

    Private Sub SimpleButton1_Click(sender As Object, e As EventArgs)

    End Sub
End Class